{include file="common/head"/}

  <script src="//unpkg.com/jquery@3.3.1/dist/jquery.min.js"></script>
  <script type="text/javascript" src="/static/ueditor/ueditor.config.js"></script>
  <script type="text/javascript" src="/static/ueditor/ueditor.all.js"></script>
<style>
    .layui-text em, .layui-word-aux{
        color: red !important;
    }
</style>
<div class="admin-main layui-anim layui-anim-upbit" ng-app="hd" ng-controller="ctrl">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>修改</legend>
    </fieldset>
    <form class="layui-form layui-form-pane">

        <!-- 类型 S -->
        <div class="layui-form-item">
            <div class="layui-form-item">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-4">
                    <select name="identity" lay-verify="required">
                        <option value=""></option>
                        {foreach $identityList as $key=>$val }
                        <option value="{$val.id}" {eq name="$val.id" value="$infoArr['identity']" } selected="" {/eq} >{$val.title}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux required">*</div>
            </div>
        </div>
        <!-- 类型 E -->

        <!-- 道馆 S -->
        <div class="layui-form-item">
            <div class="layui-form-item">
                <label class="layui-form-label">所属道馆</label>
                <div class="layui-input-4">
                    <input type="text" name="store_id" ng-model="field.store_id" disabled class="layui-input" autocomplete="off">
                </div>
                <div class="layui-form-mid layui-word-aux required">*</div>
            </div>
        </div>
        <!-- 道馆 E -->

        <!-- 用户名 S -->
        <div class="layui-form-item">
            <label class="layui-form-label"> 用户名 </label>
            <div class="layui-input-4">
                <input type="text" name="name" ng-model="field.name" lay-verify="required"  class="layui-input" autocomplete="off">
            </div>
            <div class="layui-form-mid layui-word-aux required">*</div>
        </div>
        <!-- 用户名 E -->

        <!-- 手机号 S -->
        <div class="layui-form-item">
            <label class="layui-form-label"> 手机号 </label>
            <div class="layui-input-4">
                <input type="text" name="mobile" ng-model="field.mobile" lay-verify="required"  class="layui-input" autocomplete="off">
            </div>
            <div class="layui-form-mid layui-word-aux required">*</div>
        </div>
        <!-- 手机号 E -->

        <!-- 年龄 S -->
        <div class="layui-form-item">
            <label class="layui-form-label"> 年龄 </label>
            <div class="layui-input-4">
                <input type="text" name="age" ng-model="field.age" lay-verify="required"  class="layui-input" autocomplete="off">
            </div>
            <div class="layui-form-mid layui-word-aux required">*</div>
        </div>
        <!-- 年龄 E -->

        <!-- 性别 S -->
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-4">
                <input type="radio" name="gender" value="1" {eq name="$infoArr['gender']" value="1" } checked="" {/eq} title="男">
                <input type="radio" name="gender" value="2" {eq name="$infoArr['gender']" value="2" } checked="" {/eq} title="女">
            </div>
        </div>
        <!-- 性别 E -->

        <!-- 体重 S -->
        <div class="layui-form-item">
            <label class="layui-form-label"> 体重 </label>
            <div class="layui-input-4">
                <input type="text" name="weight" ng-model="field.weight" lay-verify="required"  class="layui-input" autocomplete="off">
            </div>
            <div class="layui-form-mid layui-word-aux required">*</div>
        </div>
        <!-- 体重 E -->

        <!-- 省 S -->
        <div class="layui-form-item">
            <div class="layui-form-item">
                <label class="layui-form-label">省</label>
                <div class="layui-input-4">
                    <select name="province_id" lay-verify="required" lay-filter="changeProvinceOrCity">
                        <option value=""></option>
                        {foreach $provinceList as $key=>$val }
                            <option value="{$val.id}" data-type="province" {eq name="$val.id" value="$infoArr['province_id']" } selected="" {/eq} >{$val.title}</option>
                        {/foreach}
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux required">*</div>
            </div>
        </div>
        <!-- 省 E -->

        <!-- 市 S -->
        <div class="layui-form-item">
            <label class="layui-form-label">市</label>
            <div class="layui-input-4">
                <select name="city_id" lay-verify="required" lay-filter="changeProvinceOrCity" id="city_id">
                    <option value=""></option>
                    {foreach $cityList as $key=>$val }
                        <option value="{$val.id}" data-type="city" {eq name="$val.id" value="$infoArr['city_id']" } selected="" {/eq} >{$val.title}</option>
                    {/foreach}
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux required">*</div>
        </div>
        <!-- 市 E -->

        <!-- 区 S -->
        <div class="layui-form-item">
            <label class="layui-form-label">区</label>
            <div class="layui-input-4">
                <select name="area_id" lay-verify="required" id="area_id">
                    <option value=""></option>
                    {foreach $areaList as $key=>$val }
                        <option value="{$val.id}" {eq name="$val.id" value="$infoArr['area_id']" } selected="" {/eq} >{$val.title}</option>
                    {/foreach}
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux required">*</div>
        </div>
        <!-- 区 E -->

        <!-- 详细地址 S -->
        <div class="layui-form-item">
            <label class="layui-form-label"> 详细地址 </label>
            <div class="layui-input-4">
                <input type="text" name="address" ng-model="field.address" lay-verify="required"  class="layui-input" autocomplete="off">
            </div>
            <div class="layui-form-mid layui-word-aux required">*</div>
        </div>
        <!-- 详细地址 E -->

        <!-- 头像 S -->
        <div class="layui-form-item fieldName">
            <label class="layui-form-label">头像</label>
            <input type="hidden" name="image" id="image">
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary uploadImg" id="imageBtn"><i class="icon icon-upload3"></i>点击上传</button>
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="showImage" src="{$infoArr['image']}">
                        <input type="hidden" name="image" value="{$infoArr['image']}">
                        <p id="demoText"></p>
                    </div>
                </div>
            </div>
        </div>
        <!-- 头像 E -->

        <!-- 密码 S -->
        <div class="layui-form-item">
            <label class="layui-form-label"> 密码 </label>
            <div class="layui-input-4">
                <input type="text" name="password" ng-model="password" class="layui-input" autocomplete="off" placeholder="不修改请留空">
            </div>
        </div>
        <!-- 密码 E -->

        <!-- 排序 S -->
<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label"> 排序 </label>-->
<!--            <div class="layui-input-4">-->
<!--                <input type="text" name="sort" ng-model="field.sort" class="layui-input" autocomplete="off">-->
<!--            </div>-->
<!--        </div>-->
        <!-- 排序 E -->

        <!-- 是否禁用 S -->
        <div class="layui-form-item">
            <label class="layui-form-label">是否禁用</label>
            <div class="layui-input-4">
                <input type="radio" name="status" value="1" {eq name="$infoArr['status']" value="1" } checked="" {/eq} title="否">
                <input type="radio" name="status" value="2" {eq name="$infoArr['status']" value="2" } checked="" {/eq} title="是">
            </div>
        </div>
        <!-- 是否禁用 E -->

        <!-- 简介 S -->
        <div class="layui-form-item">
            <label class="layui-form-label">简介</label>
            <div class="layui-input-4">
                <textarea name="desc" placeholder="请输入简介" class="layui-textarea">{$infoArr['desc']}</textarea>
            </div>
        </div>
        <!-- 简介 E -->

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
<!--                <a href="{:url('index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>-->
            </div>
        </div>
    </form>
</div>
{include file="common/foot"/}

  <link href="/static/common/css/formSelects-v4.css" rel="stylesheet" />


<script src="/static/common/js/angular.min.js"></script>
<script>


  // UE.getEditor('content',{
  //       initialFrameWidth : 600,
  //       initialFrameHeight: 600,
  //    });


   layui.config({
        base: '/static/common/js/' //此处路径请自行处理, 可以使用绝对路径
    }).extend({
        formSelects: 'formSelects-v4'
    });


    var m = angular.module('hd',[]);
    m.controller('ctrl',function($scope) {
        $scope.field = {$info|raw};
        layui.use(['form','upload', 'layer','layedit','formSelects'], function () {
            var form = layui.form, layer = layui.layer,$= layui.jquery,upload = layui.upload,layedit = layui.layedit;


             var info = {$info|raw}; form.val("form", info);  if(info){ $("#pic").attr("src",info.pic); }
var info = {$info|raw}; form.val("form", info);  if(info){ $(".pic").attr("value",info.pic); }

            var formSelects = layui.formSelects;
            formSelects.btns('store_id', []);
            formSelects.on('store_id',function (id, vals, val, isAdd, isDisabled){
                $("#store_id").val(val.value);
            });


            form.on('submit(submit)', function (data) {

                // 提交到方法 默认为本身
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                data.field.id = $scope.field.id;
                 //获取编辑器的内容
                $.post("", data.field, function (res) {
                    layer.close(loading);
                    if (res.code > 0) {
                        // sessionStorage.setItem("changeData", JSON.stringify(data.field));
                        layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                            location.href = res.url;
                        });
                    } else {
                        layer.msg(res.msg, {time: 1800, icon: 2});
                    }
                });
            })

            // 切换省/市
            form.on('select(changeProvinceOrCity)',function(data){
                var selectedValue = data.value; // 获取选中的值
                var type = $(data.elem).find("option:selected").data("type");
                let childStr = `<option value=""></option>`;
                console.log(selectedValue,type);

                $.ajax({
                    type: "POST",
                    url: '{:url("CityController/getChildList")}',
                    dataType: 'json',
                    data: {
                        id: selectedValue
                    },
                    success: function (res) {
                        console.log(res.code);
                        console.log(res.data);

                        if(res.code == 200){
                            if(type == 'province'){
                                $("#city_id").empty();
                            }
                            if(type == 'city'){
                                $("#area_id").empty();
                            }

                            form.render('select'); // 更新渲染

                            $.each(res.data.list,function(key,val){
                                childStr += `<option data-type="city" value="${val.id}">${val.title}</option>`;
                                if( type == 'province' ){
                                    $("#city_id").html(childStr);
                                }
                                if( type == 'city' ){
                                    $("#area_id").html(childStr);
                                }
                            });
                            form.render('select'); // 更新渲染
                            // console.log(childStr);
                        }

                    }
                });
            });



    var uploadInst = upload.render({
            elem: ".uploadImg" ,
            url: "{:url("UpFiles/upload")}" ,
            before: function(obj){
              var _this = this;
              obj.preview(function(index, file, result){
                   _this.item.parents(".fieldName").find("img").attr("src",result)
              });
            },
            done: function(res){
                if(res.code>0){
                  this.item.parents(".fieldName").find("input[type=hidden]").val(res.url)
                }else{
                  return layer.msg("上传失败");
                }
            } ,
              error: function(res){
                var demoText = this.item.parents(".fieldName").find(".demoText");
                 demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                 demoText.find(".demo-reload").on("click", function(){
                  uploadInst.upload();
                });
              }
        });




        });
    });


    // 时间插件shi-jian-cha-jian

useLayDateMultiple('begin_time');

useLayDateMultiple('end_time');


    function useLayDateMultiple(cls) {
        layui.use('laydate', function() {
            var laydate = layui.laydate;
            lay('#' + cls).each(function() {
                laydate.render({
                    elem : this,
                    trigger : 'click',
                    type : 'datetime'
                });
            });
        });
    }


</script>
</body>
</html>